package org.jheuristics.ga.operators.selectors;

import java.util.Iterator;

import org.jheuristics.Individual;
import org.jheuristics.ga.DefaultPopulation;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.GAStatus;
import org.jheuristics.ga.Population;
import org.jheuristics.ga.multiObjective.MultiObjectiveFitness;
import org.jheuristics.ga.operators.Selector;

/**
 * TODO
 *
 * @author Marcell Manfrin, marcell@ourgrid.org, Dec 13, 2005
 */
public class NonDominatedSelector implements Selector {

	/**
	 * TODO
	 *
	 * @param population
	 * @param howMany
	 * @param status
	 * @param config
	 * @return
	 * @see org.jheuristics.ga.operators.Selector#select(org.jheuristics.ga.Population, int, org.jheuristics.ga.GAStatus, org.jheuristics.ga.GAConfig)
	 */
	public Individual[] select(Population population, int howMany, GAStatus status, GAConfig config) {
		if (null == population) {
			throw new NullPointerException();
		}
		Population result = new DefaultPopulation();
		for (Iterator it = population.iterator(); it.hasNext(); ) {
			Individual individual = (Individual) it.next();
			MultiObjectiveFitness fitness = (MultiObjectiveFitness) individual.getFitness();
			if (fitness.getRawFitness() == 0) {
				result.addIndividual(individual);
			} 
		}
		return result.toIndividualArray();
	}

}
